package com.example.yichuangyun.mvvm.ui.activity.view;

import androidx.lifecycle.MutableLiveData;

import com.example.yichuangyun.config.Constant;
import com.example.yichuangyun.model.company.GsBaseInfoModel;
import com.example.yichuangyun.model.company.GsChangeRecordDataModel;
import com.example.yichuangyun.mvvm.base.BaseViewModel;
import com.example.yichuangyun.mvvm.di.retrofit.BaseModel;
import com.example.yichuangyun.mvvm.di.retrofit.BaseNetCallback;

public class GsInfoViewModel extends BaseViewModel {

    public MutableLiveData<GsBaseInfoModel> gsBaseInfoModelMutableLiveData = new MutableLiveData<>();
    public MutableLiveData<String> errorBaseInfoMutableLiveData = new MutableLiveData<>();
    public MutableLiveData<GsChangeRecordDataModel> gsChangeRecordDataModelMutableLiveData = new MutableLiveData<>();
    public MutableLiveData<String> errorGsChangeMutableLiveData = new MutableLiveData<>();

    /**
     * 工商信息基本信息
     */
    public void getGsBaseInfo(String eid) {
        addSubscribe(mRetrofitHelper.getGsBaseInfo(eid).subscribeWith(new BaseNetCallback<GsBaseInfoModel>() {

            @Override
            public void onSuccess(BaseModel<GsBaseInfoModel> baseModel) {
                if (Constant.SUCCESS == baseModel.getCode()) {
                    if (null != baseModel.getData()) {
                        gsBaseInfoModelMutableLiveData.setValue(baseModel.getData());
                    }
                } else {
                    errorBaseInfoMutableLiveData.setValue("error");
                }
            }

            @Override
            public void onError(String message) {
                super.onError(message);
                errorBaseInfoMutableLiveData.setValue("error");
            }
        }));
    }

    /**
     * 工商变更记录
     */
    public void getGsChangeRecord(String eid) {
        addSubscribe(mRetrofitHelper.getGsChangeRecord(eid).subscribeWith(new BaseNetCallback<GsChangeRecordDataModel>() {

            @Override
            public void onSuccess(BaseModel<GsChangeRecordDataModel> baseModel) {
                if (Constant.SUCCESS == baseModel.getCode()) {
                    if (null != baseModel.getData()) {
                        gsChangeRecordDataModelMutableLiveData.setValue(baseModel.getData());
                    }
                } else {
                    errorGsChangeMutableLiveData.setValue("error");
                }
            }

            @Override
            public void onError(String message) {
                super.onError(message);
                errorGsChangeMutableLiveData.setValue("error");
            }
        }));
    }
}
